//导入vue-router
import { createRouter, createWebHistory } from "vue-router";
//导入组件
import LayoutView from "@/views/LayoutView.vue";
import LoginView from "@/views/LoginView.vue";
import HomePageView from "@/views/HomePage.vue";
// 稿件管理组件
import PeriodicalManagementView from "@/views/periodical/PeriodicalManagement.vue";
import PeriodicalRankingView from "@/views/periodical/PeriodicalRanking.vue";
import PeriodicalDetailView from "@/views/periodical/PeriodicalDetail.vue";
import OnLinePeriodicalView from "@/views/periodical/OnLinePeriodical.vue";
import RemovalOfPeriodicalView from "@/views/periodical/RemovalOfPeriodical.vue";

// 人员运营组件
import AuthorManagementView from "@/views/personnel/AuthorManagement.vue";
import EditorManagementView from "@/views/personnel/EditorManagement.vue";
import AdminManagementView from "@/views/personnel/AdminManagement.vue";
import SensitiveWordsView from "@/views/personnel/SensitiveWords.vue";

// 数据分析组件
import AiDataView from "@/views/data/AiData.vue";
// 系统相关组件
import StructureDiagramView from "@/views/system/StructureDiagram.vue";

//定义路由关系
const routes = [
  {
    path: "/login",
    component: LoginView,
    meta: { title: "芸窗登录页面页" },
  },
  {
    path: "/",
    redirect: "/homePage",
    component: LayoutView,
    children: [
      {
        path: "/homePage",
        component: HomePageView,
        meta: { title: "芸窗首页" },
      },
      {
        path: "/periodical/management",
        component: PeriodicalManagementView,
        meta: { title: "期刊管理" },
      },
      {
        path: "/periodical/ranking",
        component: PeriodicalRankingView,
        meta: { title: "稿件排行" },
      },
      {
        path: "periodical/detail",
        component: PeriodicalDetailView,
        meta: { title: "稿件详情" },
      },
      {
        path: "/periodical/online",
        component: OnLinePeriodicalView,
        meta: { title: "接收稿件" },
      },
      {
        path: "/periodical/removal",
        component: RemovalOfPeriodicalView,
        meta: { title: "拒绝稿件" },
      },
      {
        path: "/personnel/authorManagement",
        component: AuthorManagementView,
        meta: { title: "用户管理" },
      },
      {
        path: "/personnel/editorManagement",
        component: EditorManagementView,
        meta: { title: "编辑管理" },
      },
      {
        path: "/personnel/adminManagement",
        component: AdminManagementView,
        meta: { title: "管理员管理" },
      },
      {
        path: "/personnel/sensitiveWords",
        component: SensitiveWordsView,
        meta: { title: "敏感词管理" },
      },

      {
        path: "/data/aiData",
        component: AiDataView,
        meta: { title: "AI数据分析" },
      },
      {
        path: "/system/structureDiagram",
        component: StructureDiagramView,
        meta: { title: "稿件类别结构图" },
      },
    ],
  },
];

//创建路由器
const router = createRouter({
  history: createWebHistory(),
  routes: routes,
});
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  if (to.meta.favicon) {
    document.head.innerHTML = `<link rel="icon" href="${to.meta.favicon}">`;
  }
  next();
});
export default router;
